﻿using UnityEngine;
using System.Collections;

public class Enemy : MonoBehaviour 
{
	public GameObject sphereCollider;
	public GameObject player;
	public int speed = 3;
	
	public bool inSphere = false;
	
	//enemy damage
	public int life = 3;

	// Use this for initialization
	void Start () 
	{
	
	}
	
	// Update is called once per frame
	void Update () 
	{	
		if(inSphere)
		{
			transform.Translate((player.transform.position - this.transform.position).normalized * 
								Time.deltaTime * 
								speed);
		transform.lookAt(player.transform.position);
		}
		
		if(Input.GetKeyDown(KeyCode.T))
		{
			Scream ();
		}
		
		if(life<=0)
		{Destroy(this.gameObject);}
	}
	
	public void Scream()
	{
		StartCoroutine(chanceSpeed(3));
	}
	
	IEnumerator chanceSpeed(float time)
	{
		speed = -3;
     	yield return new WaitForSeconds(time);
		speed = 3;
	}
}
